#include "StdAfx.h"
#include "NavigatorPanelUI.h"
#include "ContainerUI.h"

CNavigatorPanelUI::CNavigatorPanelUI(void): m_iCurSel(-1)
{
}

CNavigatorPanelUI::~CNavigatorPanelUI(void)
{
}

LPCTSTR CNavigatorPanelUI::GetClass() const
{
	return _T("NavigatorPanelUI");
}

LPVOID CNavigatorPanelUI::GetInterface(LPCTSTR pstrName)
{
	if( _tcscmp(pstrName, _T("ListOwner")) == 0 ) return static_cast<IListOwnerUI*>(this);
	return CVerticalLayoutUI::GetInterface(pstrName);
}

int CNavigatorPanelUI::GetCurSel() const
{
	return m_iCurSel;
}

void CNavigatorPanelUI::Event(TEventUI& event)
{
	CVerticalLayoutUI::Event(event);
}

bool CNavigatorPanelUI::SelectItem(int iIndex)
{
	if( iIndex == m_iCurSel ) return true;
	if( m_iCurSel >= 0 ) {
		CControlUI* pControl = GetItem(m_iCurSel);
		IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem")));
		if( pListItem != NULL ) pListItem->Select(false);
	}
	m_iCurSel = iIndex;
	if( m_iCurSel >= 0 ) {
		CControlUI* pControl = GetItem(m_iCurSel);
		IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem")));
		if( pListItem == NULL ) return false;
		pListItem->Select(true);
		if( m_pManager != NULL ) m_pManager->SendNotify(pControl, _T("itemclick"));
	}
	if( m_pManager != NULL ) m_pManager->SendNotify(this, _T("itemselect"));
	Invalidate();
	return true;
}

bool CNavigatorPanelUI::Add(CControlUI* pControl)
{
	IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem")));
	if( pListItem != NULL ) {
		pListItem->SetOwner(this);
		pListItem->SetIndex(m_items.GetSize());
	}
	return CContainerUI::Add(pControl);
}

SIZE CNavigatorPanelUI::EstimateSize(SIZE szAvailable)
{
	return CStdSize(0, 0);
}

void CNavigatorPanelUI::DoPaint(HDC hDC, const RECT& rcPaint)
{
	COLORREF clrFirst, clrSecond;
	m_pManager->GetThemeColorPair(UICOLOR_NAVIGATOR_BACKGROUND, clrFirst, clrSecond);
	CBlueRenderEngineUI::DoPaintGradient(hDC, m_pManager, m_rcItem, clrFirst, clrSecond, false, 64);
	CVerticalLayoutUI::DoPaint(hDC, rcPaint);
}

